package cn.simon.free.redis.mq.core.producer;

import cn.simon.free.redis.mq.model.delay.DelayMessage;
import cn.simon.free.redis.mq.model.delay.DelayMessageRo;
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;

/**
 * @author simon
 * @date 2021/7/12 17:14
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
@Component
public class DelayRedisMessageProducer extends AbstractRedisMessageProducer<DelayMessage> {

    @SneakyThrows
    @Override
    protected String sendMsg(String queueName, DelayMessage message, Long delayTime) {
        DelayMessageRo delayMessageRo = new DelayMessageRo();
        delayMessageRo.setId(message.getTaskId());
        delayMessageRo.setMessage(super.mapper.writeValueAsString(message.getMessage()));

        message.setMessage(null);

        super.redisMessageDelayRoSupport.save(delayMessageRo);
        super.redisMessageSupport.push(queueName, message, delayTime);

        return super.mapper.writeValueAsString(message);
    }

}
